package com.ag.zlw.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbKnowledgeType;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;
import com.ag.zlw.service.KnowledgeTypeService;

/**
 * 专业知识类别
 * 
 * @author 钟龙伟
 * 
 */

@Scope("prototype")
@Controller("KnowledgeTypeAction")
public class KnowledgeTypeAction extends BaseAction {
	private static final long serialVersionUID = -1478025497648926124L;
	@Resource(name = "KnowledgeTypeService")
	private KnowledgeTypeService service;
	private List<TbKnowledgeType> knowledgeTypeList;
	private String message;
	private String ktId;
	private String ktName;

	TbKnowledgeType tbKnowledgeType = new TbKnowledgeType();

	public String find() {
		try {
			knowledgeTypeList = service.findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "main";
	}

	public String delete() {
		tbKnowledgeType.setKtId(ktId);
		try {
			service.delete(tbKnowledgeType);
			this.setMessage("delete success!");
		} catch (Exception e) {
			this.setMessage("delete fail!");
		}
		return "delete_success";
	}

	public String add() {
		tbKnowledgeType.setKtName(ktName);
		tbKnowledgeType.setA(IDUtil.PRESERVE);
		try {
			service.save(tbKnowledgeType);
			this.setMessage("save success!");
		} catch (Exception e) {
			this.setMessage("save fail!");
		}
		return "add_success";
	}

	public String modify() {
		tbKnowledgeType.setKtId(ktId);
		tbKnowledgeType.setKtName(ktName);
		tbKnowledgeType.setA(IDUtil.PRESERVE);
		try {
			service.modify(tbKnowledgeType);
			this.setMessage("modify success!");
		} catch (Exception e) {
			this.setMessage("modify fail!");
		}
		return "modify_success";
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getMessage() {
		return message;
	}

	public String getKtId() {
		return ktId;
	}

	public void setKtId(String ktId) {
		this.ktId = ktId;
	}

	public String getKtName() {
		return ktName;
	}

	public void setKtName(String ktName) {
		this.ktName = ktName;
	}

	public void setKnowledgeTypeList(List<TbKnowledgeType> knowledgeTypeList) {
		this.knowledgeTypeList = knowledgeTypeList;
	}

	public List<TbKnowledgeType> getKnowledgeTypeList() {
		return knowledgeTypeList;
	}
}
